
/*
 * OBSSuperUserGUI.java
 *
 * Created on Nov 10, 2010, 12:42:35 PM
 */

package GUI;
import OBS.CompareBatchReportListDate;
import Databasehandler.DBCommunicator;
import Databasehandler.DBConnector;
import Databasehandler.MySQLCommunicator;
import Errorhandler.ErrorLogger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.GregorianCalendar;
import javax.swing.event.ListSelectionListener;
import OBS.BatchReport;
import OBS.BatchReportInterval;
import OBS.BatchReportSystem;
import OBS.Customer;
import OBS.OBSSuperUser;
import OBS.OBSReportSubscriber;
import java.io.File;
import java.text.SimpleDateFormat;
/**
 *
 * @author Daniel Koch
 */
public class OBSSuperUserGUI extends javax.swing.JFrame {
    private OBSSuperUser OBSSuperUser;
    private BatchReportInterval[] batchReportIntervals;
    private Customer selectedCustomer;
    private BatchReportSystem selectedBatchReportSystem;
    private OBSReportSubscriber selectedOBSReportSubscriber;
    private BatchReportSystem selectedOBSReportSubscription;
    private BatchReportSystem[] bs;
    private ArrayList<String[]> batchReportListData = new ArrayList<String[]>();
    private int batchReportListPage = 0;
    private BatchReportSystem[] currentBatchReportSystems;
    private String logDir = System.getProperty("user.dir") + File.separator+"log"+File.separator;
    private String logName = "OBSUserGUIErrors.log";

    ListSelectionListener customerListListener = new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                customerListValueChanged(evt);
            }
        };

    ListSelectionListener batchReportSystemListListener = new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                batchReportSystemListValueChanged(evt);
            }
        };

    ListSelectionListener OBSReportSubscriberListListener = new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                OBSReportSubscriberListValueChanged(evt);
            }
        };
    
    public OBSSuperUserGUI() {
        initComponents();
        groupBatchReportListButtons();
        this.customerList.addListSelectionListener(customerListListener);
        this.batchReportSystemList.addListSelectionListener(batchReportSystemListListener);
        this.OBSReportSubscriberList.addListSelectionListener(OBSReportSubscriberListListener);
        try {
            DBConnector connector = new DBConnector();
            DBCommunicator communicator = new MySQLCommunicator(connector);
            this.OBSSuperUser = new OBSSuperUser(communicator);
            this.batchReportIntervals = this.OBSSuperUser.getBatchReportIntervals();
            this.currentBatchReportSystems = this.OBSSuperUser.getCurrentBatchReportSystems();
        }
        catch(Exception e) {
            ShowPopUp.showMessage("Databasefejl: " + e.getMessage() + " \n Kontakt Driften");
             // send fejlmeddelse til ErrorLog
            try {
                ErrorLogger.writeToErrorLog(logDir+logName,"Databasefejl: " + e.getMessage());
            } catch (Exception e1){} // fejl hvis der ikke kan skrives til log kan ikke håndteres, SKRIV_TIL_OS_EVENT_LOG
            System.exit(0);
        }
        refreshLists();
        
    }

    private void refreshLists() {
        this.customerList.removeListSelectionListener(customerListListener);
        this.OBSReportSubscriberList.removeListSelectionListener(OBSReportSubscriberListListener);
        updateCustomerList();
        updateBatchReportSystemList();
        updateOBSReportSubscriberList();
        updateOBSReportSubscriptionList();
        this.customerList.addListSelectionListener(customerListListener);
        this.OBSReportSubscriberList.addListSelectionListener(OBSReportSubscriberListListener);
        loadListState();
    }

    private void saveListState() {
        Object customer  = this.customerList.getSelectedValue();
        if(customer instanceof Customer) {
            this.selectedCustomer = (Customer)customer;
        }
        else {
            this.selectedCustomer = null;
        }
        Object batchReportSystem  = this.batchReportSystemList.getSelectedValue();
        if(batchReportSystem instanceof BatchReportSystem) {
            this.selectedBatchReportSystem = (BatchReportSystem)batchReportSystem;
        }
        else {
            this.selectedBatchReportSystem = null;
        }
        Object OBSReportSubscriber  = this.OBSReportSubscriberList.getSelectedValue();
        if(OBSReportSubscriber instanceof OBSReportSubscriber) {
            this.selectedOBSReportSubscriber = (OBSReportSubscriber)OBSReportSubscriber;
        }
        else {
            this.selectedOBSReportSubscriber = null;
        }
    }

    private void loadListState() {
        this.customerList.setSelectedValue(this.selectedCustomer, true);
        this.batchReportSystemList.setSelectedValue(this.selectedBatchReportSystem, true);
        this.OBSReportSubscriberList.setSelectedValue(this.selectedOBSReportSubscriber, true);
    }

    private String dateToString(GregorianCalendar gc) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return format.format(gc.getTime());
    }

    private void groupBatchReportListButtons() {
        this.batchReportListButtonGroup.add(this.batchReportListCurrentRadioButton);
        this.batchReportListButtonGroup.add(this.batchReportListLogRadioButton);

    }

    private void customerListValueChanged(javax.swing.event.ListSelectionEvent evt) {
        if(this.customerList.getSelectedValue() != null) {
            this.selectedCustomer = (Customer)this.customerList.getSelectedValue();
        }
        updateBatchReportSystemList();
        this.OBSReportSubscriberList.removeListSelectionListener(OBSReportSubscriberListListener);
        updateOBSReportSubscriberList();
        this.OBSReportSubscriberList.addListSelectionListener(OBSReportSubscriberListListener);
        updateOBSReportSubscriptionList();
        
    }

    private void OBSReportSubscriberListValueChanged(javax.swing.event.ListSelectionEvent evt) {
        if(this.OBSReportSubscriberList.getSelectedValue() instanceof OBSReportSubscriber) {
            this.selectedOBSReportSubscriber = (OBSReportSubscriber)this.OBSReportSubscriberList.getSelectedValue();
        }
        updateOBSReportSubscriptionList();
    }

    private void batchReportSystemListValueChanged(javax.swing.event.ListSelectionEvent evt) {
        if(this.batchReportSystemList.getSelectedValue() instanceof BatchReportSystem) {
            this.selectedBatchReportSystem = (BatchReportSystem)this.batchReportSystemList.getSelectedValue();
        }
    }

    public void updateCustomerList() {
        try {
            Object[] o = this.OBSSuperUser.getCustomers();
            if(o.length == 0) {
                this.customerList.setListData(new String[]{"Ingen"});
            }
            else {
                this.customerList.setListData(o);
            }
            this.customerList.setSelectedIndex(0);
        }
        catch(Exception e) {
            e.printStackTrace();
        }
    }

    public void updateBatchReportSystemList() {
        try {
            Object o = this.customerList.getSelectedValue();
            Object[] items = new Object[1];
            if(o instanceof Customer) {
                Customer customer = (Customer)this.customerList.getSelectedValue();
                BatchReportSystem[] batchReportSystems = customer.getBatchReportSystems();
                if(batchReportSystems.length == 0) {
                    items[0] = "Ingen";
                }
                else {
                    items = batchReportSystems;
                }
                this.batchReportSystemFilterLabel.setText(this.customerList.getSelectedValue().toString());
            }
            else {
                items[0] = "Ingen";
                this.batchReportSystemFilterLabel.setText("Ingen");
            }
            this.batchReportSystemList.setListData(items);
            this.batchReportSystemList.setSelectedIndex(0);
        }
        catch(Exception e) {
            e.printStackTrace();
        }
    }

    public void updateOBSReportSubscriberList() {
        try {
            Object o = this.customerList.getSelectedValue();
            Object[] items = new Object[1];;
            if(o instanceof Customer) {
                Customer customer = (Customer)this.customerList.getSelectedValue();
                OBSReportSubscriber[] OBSReportSubscribers = customer.getOBSReportSubscribers();
                if(OBSReportSubscribers.length == 0) {
                    items[0] = "Ingen";
                }
                else {
                    items = OBSReportSubscribers;
                }
                
            }
            else {
                items[0] = "Ingen";
            }
            if(this.customerList.getSelectedValue() != null) {
                this.OBSReportSubscriberFilterLabel.setText(this.customerList.getSelectedValue().toString());
            }
            else {
                this.OBSReportSubscriberFilterLabel.setText("Ingen");
            }
            this.OBSReportSubscriberList.setListData(items);
            this.OBSReportSubscriberList.setSelectedIndex(0);
        }
        catch(Exception e) {
            e.printStackTrace();
        }
    }

    public void updateOBSReportSubscriptionList() {
        try {
            Object o = this.OBSReportSubscriberList.getSelectedValue();
            Object[] items = new Object[1];
            if(o instanceof OBSReportSubscriber) {
                OBSReportSubscriber OBSReportSubscriber = (OBSReportSubscriber)this.OBSReportSubscriberList.getSelectedValue();
                BatchReportSystem[] b = OBSReportSubscriber.getOBSReportSubscription().getBatchReportSystems();
                if(b.length == 0) {
                    items[0] = "Ingen";
                }
                else {
                    items = (Object[])b;
                }
            }
            else {
                items[0] = "Ingen";
                
            }
            if(this.OBSReportSubscriberList.getSelectedValue() != null) {
                this.OBSReportSubscriptionFilterLabel.setText(this.OBSReportSubscriberList.getSelectedValue().toString());
            }
            else {
                this.OBSReportSubscriptionFilterLabel.setText("Ingen");
            }
            this.OBSReportSubscriptionList.setListData(items);
            this.OBSReportSubscriptionList.setSelectedIndex(0);
        }
        catch(Exception e) {
            e.printStackTrace();
        }
    }

    public void setBatchReportListData(BatchReportSystem batchReportSystem) {
        if(this.batchReportListCurrentRadioButton.isSelected() && Arrays.asList(this.currentBatchReportSystems).contains(batchReportSystem)) {
            BatchReport[] currentBatchReports = batchReportSystem.getCurrentBatchReports();
            if(currentBatchReports.length == 0) {
                String batchReportSystemName = batchReportSystem.getName();
                String batchReportName = "";
                String timeRecieved = "Ikke modtaget";
                this.batchReportListData.add(new String[]{batchReportSystemName, batchReportName, timeRecieved});
            }
            else {
                for(int i = 0;i < currentBatchReports.length;i++) {
                    String batchReportSystemName = batchReportSystem.getName();
                    String batchReportName = currentBatchReports[i].getName();
                    String timeRecieved = dateToString(currentBatchReports[i].getTimeRecieved());
                    this.batchReportListData.add(new String[]{batchReportSystemName, batchReportName, timeRecieved});
                }
            }
        }
        else {
            BatchReport[] batchReports = batchReportSystem.getBatchReports();
            for(int i = 0;i < batchReports.length;i++) {
                String batchReportSystemName = batchReportSystem.getName();
                String batchReportName = batchReports[i].getName();
                String timeRecieved = dateToString(batchReports[i].getTimeRecieved());
                this.batchReportListData.add(new String[]{batchReportSystemName, batchReportName, timeRecieved});
            }
        }
        Collections.sort(this.batchReportListData, new CompareBatchReportListDate());
    }

    public void setBatchReportListData(BatchReportSystem[] batchReportSystems) {
        for(int i = 0;i < batchReportSystems.length;i++) {
            setBatchReportListData(batchReportSystems[i]);
        }
    }

    public void updateBatchReportList() {
        int offset = this.batchReportList.getRowCount() * this.batchReportListPage;
        for(int i = 0;(i < this.batchReportList.getRowCount()) && (i + offset < this.batchReportListData.size());i++) {
            String batchReportSystemName = this.batchReportListData.get(i + offset)[0];
            String batchReportName = this.batchReportListData.get(i + offset)[1];
            String timeRecieved = this.batchReportListData.get(i + offset)[2];
            this.batchReportList.setValueAt(batchReportSystemName, i, 0);
            this.batchReportList.setValueAt(batchReportName, i, 1);
            this.batchReportList.setValueAt(timeRecieved, i, 2);
        }
        this.batchReportListCounter.setText((offset + 1) + "-" + ((this.batchReportListPage + 1) * this.batchReportList.getRowCount()) + " (" + this.batchReportListData.size() + ")");
    }

    public void clearBatchReportList() {
        for(int i = 0;i < this.batchReportList.getRowCount();i++) {
            this.batchReportList.setValueAt("", i, 0);
            this.batchReportList.setValueAt("", i, 1);
            this.batchReportList.setValueAt("", i, 2);
        }
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        batchReportListButtonGroup = new javax.swing.ButtonGroup();
        jScrollPane1 = new javax.swing.JScrollPane();
        batchReportList = new javax.swing.JTable();
        batchReportListTitle = new javax.swing.JLabel();
        batchReportListEndButton = new javax.swing.JButton();
        batchReportListStartButton = new javax.swing.JButton();
        batchReportListBackwardButton = new javax.swing.JButton();
        batchReportListForwardButton = new javax.swing.JButton();
        jScrollPane6 = new javax.swing.JScrollPane();
        customerList = new javax.swing.JList();
        customerListLabel = new javax.swing.JLabel();
        batchReportListCounter = new javax.swing.JLabel();
        createCustomerButton = new javax.swing.JButton();
        deleteCustomerButton = new javax.swing.JButton();
        editCustomerButton = new javax.swing.JButton();
        showCustomerReportsButton = new javax.swing.JButton();
        batchReportSystemListLabel = new javax.swing.JLabel();
        editBatchReportSystemButton = new javax.swing.JButton();
        deleteBatchReportSystemButton = new javax.swing.JButton();
        createBatchReportSystemButton = new javax.swing.JButton();
        jScrollPane7 = new javax.swing.JScrollPane();
        batchReportSystemList = new javax.swing.JList();
        showBatchReportSystemReportsButton = new javax.swing.JButton();
        OBSReportSubscriberListLabel = new javax.swing.JLabel();
        editOBSReportSubscriberButton = new javax.swing.JButton();
        deleteOBSReportSubscriberButton = new javax.swing.JButton();
        createOBSReportSubscriberButton = new javax.swing.JButton();
        jScrollPane8 = new javax.swing.JScrollPane();
        OBSReportSubscriberList = new javax.swing.JList();
        showOBSReportSubscriberReportsButton = new javax.swing.JButton();
        OBSReportSubscriptionListLabel = new javax.swing.JLabel();
        editOBSReportSubscriptionButton = new javax.swing.JButton();
        jScrollPane9 = new javax.swing.JScrollPane();
        OBSReportSubscriptionList = new javax.swing.JList();
        showOBSReportSubscriptionReportsButton = new javax.swing.JButton();
        batchReportListFilter = new javax.swing.JLabel();
        batchReportSystemFilterLabel = new javax.swing.JLabel();
        OBSReportSubscriberFilterLabel = new javax.swing.JLabel();
        OBSReportSubscriptionFilterLabel = new javax.swing.JLabel();
        seperator = new javax.swing.JSeparator();
        deleteOBSReportSubscriptionButton = new javax.swing.JButton();
        batchReportListLogRadioButton = new javax.swing.JRadioButton();
        batchReportListCurrentRadioButton = new javax.swing.JRadioButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("OBS Superbruger");
        setResizable(false);

        batchReportList.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null}
            },
            new String [] {
                "Batchsystem", "Batchrapportnavn", "Modtaget"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        batchReportList.setFocusable(false);
        batchReportList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        batchReportList.getTableHeader().setReorderingAllowed(false);
        jScrollPane1.setViewportView(batchReportList);

        batchReportListTitle.setText("Viser rapporter for:");

        batchReportListEndButton.setText(">>");
        batchReportListEndButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                batchReportListEndButtonActionPerformed(evt);
            }
        });

        batchReportListStartButton.setText("<<");
        batchReportListStartButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                batchReportListStartButtonActionPerformed(evt);
            }
        });

        batchReportListBackwardButton.setText("<");
        batchReportListBackwardButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                batchReportListBackwardButtonActionPerformed(evt);
            }
        });

        batchReportListForwardButton.setText(">");
        batchReportListForwardButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                batchReportListForwardButtonActionPerformed(evt);
            }
        });

        customerList.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Kunder" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        customerList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane6.setViewportView(customerList);

        customerListLabel.setText("Kunder");

        batchReportListCounter.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        batchReportListCounter.setText("1-25 (0)");

        createCustomerButton.setText("Opret");
        createCustomerButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                createCustomerButtonActionPerformed(evt);
            }
        });

        deleteCustomerButton.setText("Slet");
        deleteCustomerButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteCustomerButtonActionPerformed(evt);
            }
        });

        editCustomerButton.setText("Redigér");
        editCustomerButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editCustomerButtonActionPerformed(evt);
            }
        });

        showCustomerReportsButton.setText("Vis rapporter");
        showCustomerReportsButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                showCustomerReportsButtonActionPerformed(evt);
            }
        });

        batchReportSystemListLabel.setText("Batchsystemer:");

        editBatchReportSystemButton.setText("Redigér");
        editBatchReportSystemButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editBatchReportSystemButtonActionPerformed(evt);
            }
        });

        deleteBatchReportSystemButton.setText("Slet");
        deleteBatchReportSystemButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteBatchReportSystemButtonActionPerformed(evt);
            }
        });

        createBatchReportSystemButton.setText("Opret");
        createBatchReportSystemButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                createBatchReportSystemButtonActionPerformed(evt);
            }
        });

        batchReportSystemList.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Batchrapportsystemer" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        batchReportSystemList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane7.setViewportView(batchReportSystemList);

        showBatchReportSystemReportsButton.setText("Vis rapporter");
        showBatchReportSystemReportsButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                showBatchReportSystemReportsButtonActionPerformed(evt);
            }
        });

        OBSReportSubscriberListLabel.setText("Abonnenter:");

        editOBSReportSubscriberButton.setText("Redigér");
        editOBSReportSubscriberButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editOBSReportSubscriberButtonActionPerformed(evt);
            }
        });

        deleteOBSReportSubscriberButton.setText("Slet");
        deleteOBSReportSubscriberButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteOBSReportSubscriberButtonActionPerformed(evt);
            }
        });

        createOBSReportSubscriberButton.setText("Opret");
        createOBSReportSubscriberButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                createOBSReportSubscriberButtonActionPerformed(evt);
            }
        });

        OBSReportSubscriberList.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Abonnenter" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        OBSReportSubscriberList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane8.setViewportView(OBSReportSubscriberList);

        showOBSReportSubscriberReportsButton.setText("Vis rapporter");
        showOBSReportSubscriberReportsButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                showOBSReportSubscriberReportsButtonActionPerformed(evt);
            }
        });

        OBSReportSubscriptionListLabel.setText("Abonnement:");

        editOBSReportSubscriptionButton.setText("Redigér");
        editOBSReportSubscriptionButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editOBSReportSubscriptionButtonActionPerformed(evt);
            }
        });

        OBSReportSubscriptionList.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Abonnementer" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        OBSReportSubscriptionList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane9.setViewportView(OBSReportSubscriptionList);

        showOBSReportSubscriptionReportsButton.setText("Vis rapporter");
        showOBSReportSubscriptionReportsButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                showOBSReportSubscriptionReportsButtonActionPerformed(evt);
            }
        });

        batchReportListFilter.setText("Kunde/Batchsystem/Abonnent/Abonnement");

        batchReportSystemFilterLabel.setText("Kunde");

        OBSReportSubscriberFilterLabel.setText("Kunde");

        OBSReportSubscriptionFilterLabel.setText("Abonnent");

        deleteOBSReportSubscriptionButton.setText("Slet alle");
        deleteOBSReportSubscriptionButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteOBSReportSubscriptionButtonActionPerformed(evt);
            }
        });

        batchReportListLogRadioButton.setSelected(true);
        batchReportListLogRadioButton.setText("Vis log");

        batchReportListCurrentRadioButton.setText("Vis aktuelle");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 936, Short.MAX_VALUE)
                    .addComponent(seperator, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 936, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(jScrollPane6)
                                .addComponent(showCustomerReportsButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                    .addComponent(createCustomerButton)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(editCustomerButton)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(deleteCustomerButton)))
                            .addComponent(customerListLabel))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(jScrollPane7)
                                .addComponent(showBatchReportSystemReportsButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                    .addComponent(createBatchReportSystemButton)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(editBatchReportSystemButton)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(deleteBatchReportSystemButton)))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(batchReportSystemListLabel)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(batchReportSystemFilterLabel)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(jScrollPane8)
                                .addComponent(showOBSReportSubscriberReportsButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                    .addComponent(createOBSReportSubscriberButton)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(editOBSReportSubscriberButton)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(deleteOBSReportSubscriberButton)))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(OBSReportSubscriberListLabel)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(OBSReportSubscriberFilterLabel)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane9, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 243, Short.MAX_VALUE)
                            .addComponent(showOBSReportSubscriptionReportsButton, javax.swing.GroupLayout.DEFAULT_SIZE, 243, Short.MAX_VALUE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(OBSReportSubscriptionListLabel)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(OBSReportSubscriptionFilterLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 172, Short.MAX_VALUE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(editOBSReportSubscriptionButton, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(deleteOBSReportSubscriptionButton, javax.swing.GroupLayout.DEFAULT_SIZE, 128, Short.MAX_VALUE))))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(batchReportListTitle)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(batchReportListFilter)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 447, Short.MAX_VALUE)
                        .addComponent(batchReportListCounter, javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(batchReportListLogRadioButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(batchReportListCurrentRadioButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 578, Short.MAX_VALUE)
                        .addComponent(batchReportListStartButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(batchReportListBackwardButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(batchReportListForwardButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(batchReportListEndButton)))
                .addContainerGap())
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {batchReportListBackwardButton, batchReportListEndButton, batchReportListForwardButton, batchReportListStartButton});

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {createBatchReportSystemButton, createCustomerButton, createOBSReportSubscriberButton, deleteBatchReportSystemButton, deleteCustomerButton, deleteOBSReportSubscriberButton, editBatchReportSystemButton, editCustomerButton, editOBSReportSubscriberButton});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(customerListLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(createCustomerButton)
                            .addComponent(deleteCustomerButton)
                            .addComponent(editCustomerButton))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(showCustomerReportsButton))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(batchReportSystemListLabel)
                            .addComponent(batchReportSystemFilterLabel))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(createBatchReportSystemButton)
                            .addComponent(deleteBatchReportSystemButton)
                            .addComponent(editBatchReportSystemButton))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(showBatchReportSystemReportsButton))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(OBSReportSubscriberListLabel)
                            .addComponent(OBSReportSubscriberFilterLabel))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(createOBSReportSubscriberButton)
                            .addComponent(editOBSReportSubscriberButton))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(showOBSReportSubscriberReportsButton))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(OBSReportSubscriptionListLabel)
                            .addComponent(OBSReportSubscriptionFilterLabel))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(editOBSReportSubscriptionButton)
                            .addComponent(deleteOBSReportSubscriberButton)
                            .addComponent(deleteOBSReportSubscriptionButton))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(showOBSReportSubscriptionReportsButton)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(seperator, javax.swing.GroupLayout.PREFERRED_SIZE, 3, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(batchReportListTitle)
                    .addComponent(batchReportListCounter)
                    .addComponent(batchReportListFilter))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 343, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(batchReportListEndButton)
                        .addComponent(batchReportListForwardButton)
                        .addComponent(batchReportListBackwardButton)
                        .addComponent(batchReportListStartButton))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(batchReportListLogRadioButton)
                        .addComponent(batchReportListCurrentRadioButton)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void batchReportListStartButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_batchReportListStartButtonActionPerformed
        this.batchReportListPage = 0;
        clearBatchReportList();
        updateBatchReportList();
    }//GEN-LAST:event_batchReportListStartButtonActionPerformed

    private void createCustomerButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createCustomerButtonActionPerformed
        Customer customer = ShowPopUp.createCustomer();
        if(customer != null) {
            try {
                this.selectedCustomer = customer;
                this.OBSSuperUser.createCustomer(customer);
                refreshLists();
            }
            catch(Exception e) {
                ShowPopUp.showMessage("Databasefejl: " + e.getMessage() + " \n Kontakt Driften");
                // send fejlmeddelse til ErrorLog
                try {
                    ErrorLogger.writeToErrorLog(logDir+logName,"Databasefejl: " + e.getMessage());
                }
                catch (Exception e1){} // fejl hvis der ikke kan skrives til log kan ikke håndteres, SKRIV_TIL_OS_EVENT_LOG
                System.exit(0);
            }
        }
    }//GEN-LAST:event_createCustomerButtonActionPerformed

    private void createBatchReportSystemButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createBatchReportSystemButtonActionPerformed
        Object o = this.customerList.getSelectedValue();
        if(o instanceof Customer) {
            Customer customer = (Customer)o;
            BatchReportSystem batchReportSystem = ShowPopUp.createBatchReportSystem((Customer)customer, this.batchReportIntervals);
            if(batchReportSystem != null) {
                try {
                    this.OBSSuperUser.createBatchReportSystem(batchReportSystem, (Customer)customer);
                    saveListState();
                    refreshLists();
                }
                catch(Exception e) {
                    ShowPopUp.showMessage("Der opstod en fejl! Kontakt systemadministratoren.\n\nFejlbesked: " + e.getMessage());
                }
            }
        }
    }//GEN-LAST:event_createBatchReportSystemButtonActionPerformed

    private void createOBSReportSubscriberButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createOBSReportSubscriberButtonActionPerformed
        Object o = this.customerList.getSelectedValue();
        if(o instanceof Customer) {
            Customer customer = (Customer)o;
            OBSReportSubscriber OBSReportSubscriber = ShowPopUp.createOBSReportSubscriber();
            if(OBSReportSubscriber != null) {
                this.OBSSuperUser.createOBSReportSubscriber(OBSReportSubscriber, (Customer)customer);
                saveListState();
                refreshLists();
            }
        }
    }//GEN-LAST:event_createOBSReportSubscriberButtonActionPerformed

    private void editCustomerButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editCustomerButtonActionPerformed
        ShowPopUp.editCustomer((Customer)this.customerList.getSelectedValue());
        try {
            this.OBSSuperUser.editCustomer((Customer)this.customerList.getSelectedValue());
            saveListState();
            refreshLists();
        }
        catch(Exception e) {
                ShowPopUp.showMessage("Databasefejl: " + e.getMessage() + " \n Kontakt Driften");
                // send fejlmeddelse til ErrorLog
                try {
                    ErrorLogger.writeToErrorLog(logDir+logName,"Databasefejl: " + e.getMessage());
                }
                catch (Exception e1){} // fejl hvis der ikke kan skrives til log kan ikke håndteres, SKRIV_TIL_OS_EVENT_LOG
                System.exit(0);
        }
    }//GEN-LAST:event_editCustomerButtonActionPerformed

    private void deleteCustomerButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteCustomerButtonActionPerformed
        Object o = this.customerList.getSelectedValue();
        if(o instanceof Customer) {
            Customer customer = (Customer)o;
            if(ShowPopUp.confirmDelete("Er du sikker på, at du vil slette \"" + customer.getName() + "\" med alle tilhørende batchrapportsystemer og abonnenter?")) {
                try {
                    this.OBSSuperUser.deleteCustomer(customer);
                    refreshLists();
                }
                catch(Exception e) {
                ShowPopUp.showMessage("Databasefejl: " + e.getMessage() + " \n Kontakt Driften");
                // send fejlmeddelse til ErrorLog
                try {
                    ErrorLogger.writeToErrorLog(logDir+logName,"Databasefejl: " + e.getMessage());
                }
                catch (Exception e1){} // fejl hvis der ikke kan skrives til log kan ikke håndteres, SKRIV_TIL_OS_EVENT_LOG
                System.exit(0);
                }
            }
        }
    }//GEN-LAST:event_deleteCustomerButtonActionPerformed

    private void editBatchReportSystemButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editBatchReportSystemButtonActionPerformed
        Object o = this.batchReportSystemList.getSelectedValue();
        if(o instanceof BatchReportSystem) {
            BatchReportSystem batchReportSystem = (BatchReportSystem)o;
            if(ShowPopUp.editBatchReportSystem(batchReportSystem, this.batchReportIntervals) != null) {
                this.OBSSuperUser.editBatchReportSystem(batchReportSystem);
                saveListState();
                refreshLists();
            }
        }
    }//GEN-LAST:event_editBatchReportSystemButtonActionPerformed

    private void deleteBatchReportSystemButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteBatchReportSystemButtonActionPerformed
        Object o = this.batchReportSystemList.getSelectedValue();
        if(o instanceof BatchReportSystem) {
            BatchReportSystem batchReportSystem = (BatchReportSystem)o;
            if(ShowPopUp.confirmDelete("Er du sikker på, at du vil slette \"" + batchReportSystem.getName() + "\" med alle tilhørende batchrapportsystemer og abonnenter?")) {
                this.OBSSuperUser.deleteBatchReportSystem(batchReportSystem);
                saveListState();
                refreshLists();
            }
        }
    }//GEN-LAST:event_deleteBatchReportSystemButtonActionPerformed

    private void editOBSReportSubscriberButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editOBSReportSubscriberButtonActionPerformed
        Object o = this.OBSReportSubscriberList.getSelectedValue();
        if(o instanceof OBSReportSubscriber) {
            OBSReportSubscriber OBSReportSubscriber = (OBSReportSubscriber)o;
            if(ShowPopUp.editOBSReportSubscriber(OBSReportSubscriber) != null) {
                this.OBSSuperUser.editOBSReportSubscriber(OBSReportSubscriber);
                saveListState();
                refreshLists();
            }
        }
    }//GEN-LAST:event_editOBSReportSubscriberButtonActionPerformed

    private void deleteOBSReportSubscriberButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteOBSReportSubscriberButtonActionPerformed
        Object o = this.OBSReportSubscriberList.getSelectedValue();
        if(o instanceof OBSReportSubscriber) {
            OBSReportSubscriber OBSReportSubscriber = (OBSReportSubscriber)o;
            if(ShowPopUp.confirmDelete("Er du sikker på, at du vil slette \"" + OBSReportSubscriber.getName() + "\"?")) {
                this.OBSSuperUser.deleteOBSReportSubscriber(OBSReportSubscriber);
                saveListState();
                refreshLists();
            }
        }
    }//GEN-LAST:event_deleteOBSReportSubscriberButtonActionPerformed

    private void editOBSReportSubscriptionButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editOBSReportSubscriptionButtonActionPerformed
        Object o = this.OBSReportSubscriberList.getSelectedValue();
        if(o instanceof OBSReportSubscriber) {
            Customer customer = (Customer)this.customerList.getSelectedValue();
            OBSReportSubscriber OBSReportSubscriber = (OBSReportSubscriber)o;
            if(ShowPopUp.editOBSReportSubscription(OBSReportSubscriber, customer.getBatchReportSystems()) != null) {
                this.OBSSuperUser.editOBSReportSubscription(OBSReportSubscriber);
                saveListState();
                refreshLists();
            }
        }
    }//GEN-LAST:event_editOBSReportSubscriptionButtonActionPerformed

    private void deleteOBSReportSubscriptionButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteOBSReportSubscriptionButtonActionPerformed
        Object o = this.OBSReportSubscriberList.getSelectedValue();
        if(o instanceof OBSReportSubscriber) {
            OBSReportSubscriber OBSReportSubscriber = (OBSReportSubscriber)o;
            OBSReportSubscriber.setOBSReportSubscription(null);
            this.OBSSuperUser.editOBSReportSubscription(OBSReportSubscriber);
            saveListState();
            refreshLists();
        }
    }//GEN-LAST:event_deleteOBSReportSubscriptionButtonActionPerformed

    private void showBatchReportSystemReportsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showBatchReportSystemReportsButtonActionPerformed
        Object o = this.batchReportSystemList.getSelectedValue();
        if(o instanceof BatchReportSystem) {
            BatchReportSystem batchReportSystem = (BatchReportSystem)o;
            this.batchReportListData.clear();
            clearBatchReportList();
            this.batchReportListPage = 0;
            setBatchReportListData(batchReportSystem);
            updateBatchReportList();
            batchReportListFilter.setText("Batchsystem: " + batchReportSystem.getName());
        }
    }//GEN-LAST:event_showBatchReportSystemReportsButtonActionPerformed

    private void showCustomerReportsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showCustomerReportsButtonActionPerformed
        Object o = this.customerList.getSelectedValue();
        if(o instanceof Customer) {
            Customer customer = (Customer)o;
            this.batchReportListData.clear();
            clearBatchReportList();
            this.batchReportListPage = 0;
            setBatchReportListData(customer.getBatchReportSystems());
            updateBatchReportList();
            batchReportListFilter.setText("Kunde: " + customer.getName());
        }
    }//GEN-LAST:event_showCustomerReportsButtonActionPerformed

    private void showOBSReportSubscriberReportsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showOBSReportSubscriberReportsButtonActionPerformed
        Object o = this.OBSReportSubscriberList.getSelectedValue();
        if(o instanceof OBSReportSubscriber) {
            OBSReportSubscriber OBSReportSubscriber = (OBSReportSubscriber)o;
            this.batchReportListData.clear();
            clearBatchReportList();
            this.batchReportListPage = 0;
            setBatchReportListData(OBSReportSubscriber.getOBSReportSubscription().getBatchReportSystems());
            updateBatchReportList();
            batchReportListFilter.setText("Abonnent: " + OBSReportSubscriber.getName());
        }
    }//GEN-LAST:event_showOBSReportSubscriberReportsButtonActionPerformed

    private void showOBSReportSubscriptionReportsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showOBSReportSubscriptionReportsButtonActionPerformed
        Object o = this.OBSReportSubscriptionList.getSelectedValue();
        if(o instanceof BatchReportSystem) {
            BatchReportSystem batchReportSystem = (BatchReportSystem)o;
            this.batchReportListData.clear();
            clearBatchReportList();
            this.batchReportListPage = 0;
            setBatchReportListData(batchReportSystem);
            updateBatchReportList();
            batchReportListFilter.setText("Batchsystem: " + batchReportSystem.getName());
        }
    }//GEN-LAST:event_showOBSReportSubscriptionReportsButtonActionPerformed

    private void batchReportListForwardButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_batchReportListForwardButtonActionPerformed
        if((this.batchReportList.getRowCount() * (this.batchReportListPage + 1)) < this.batchReportListData.size()) {
            this.batchReportListPage++;
            clearBatchReportList();
            updateBatchReportList();
        }
    }//GEN-LAST:event_batchReportListForwardButtonActionPerformed

    private void batchReportListBackwardButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_batchReportListBackwardButtonActionPerformed
        if(this.batchReportListPage > 0) {
            this.batchReportListPage--;
            clearBatchReportList();
            updateBatchReportList();
        }
    }//GEN-LAST:event_batchReportListBackwardButtonActionPerformed

    private void batchReportListEndButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_batchReportListEndButtonActionPerformed
        this.batchReportListPage = (int)Math.ceil(this.batchReportListData.size()/this.batchReportList.getRowCount());
        clearBatchReportList();
        updateBatchReportList();
    }//GEN-LAST:event_batchReportListEndButtonActionPerformed
   

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel OBSReportSubscriberFilterLabel;
    private javax.swing.JList OBSReportSubscriberList;
    private javax.swing.JLabel OBSReportSubscriberListLabel;
    private javax.swing.JLabel OBSReportSubscriptionFilterLabel;
    private javax.swing.JList OBSReportSubscriptionList;
    private javax.swing.JLabel OBSReportSubscriptionListLabel;
    private javax.swing.JTable batchReportList;
    private javax.swing.JButton batchReportListBackwardButton;
    private javax.swing.ButtonGroup batchReportListButtonGroup;
    private javax.swing.JLabel batchReportListCounter;
    private javax.swing.JRadioButton batchReportListCurrentRadioButton;
    private javax.swing.JButton batchReportListEndButton;
    private javax.swing.JLabel batchReportListFilter;
    private javax.swing.JButton batchReportListForwardButton;
    private javax.swing.JRadioButton batchReportListLogRadioButton;
    private javax.swing.JButton batchReportListStartButton;
    private javax.swing.JLabel batchReportListTitle;
    private javax.swing.JLabel batchReportSystemFilterLabel;
    private javax.swing.JList batchReportSystemList;
    private javax.swing.JLabel batchReportSystemListLabel;
    private javax.swing.JButton createBatchReportSystemButton;
    private javax.swing.JButton createCustomerButton;
    private javax.swing.JButton createOBSReportSubscriberButton;
    private javax.swing.JList customerList;
    private javax.swing.JLabel customerListLabel;
    private javax.swing.JButton deleteBatchReportSystemButton;
    private javax.swing.JButton deleteCustomerButton;
    private javax.swing.JButton deleteOBSReportSubscriberButton;
    private javax.swing.JButton deleteOBSReportSubscriptionButton;
    private javax.swing.JButton editBatchReportSystemButton;
    private javax.swing.JButton editCustomerButton;
    private javax.swing.JButton editOBSReportSubscriberButton;
    private javax.swing.JButton editOBSReportSubscriptionButton;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JScrollPane jScrollPane7;
    private javax.swing.JScrollPane jScrollPane8;
    private javax.swing.JScrollPane jScrollPane9;
    private javax.swing.JSeparator seperator;
    private javax.swing.JButton showBatchReportSystemReportsButton;
    private javax.swing.JButton showCustomerReportsButton;
    private javax.swing.JButton showOBSReportSubscriberReportsButton;
    private javax.swing.JButton showOBSReportSubscriptionReportsButton;
    // End of variables declaration//GEN-END:variables

}
